package com.example.base_mvvm.money;

import android.app.Application;

import androidx.room.Room;

public class AppDataBaseUtils {
    private AppDataBaseUtils() {
    }
    private static final String TABLE_NAME="name.db";
    private static volatile AppDataBaseUtils appDataBaseUtils;

    public static AppDataBaseUtils getInstance(){
        if(appDataBaseUtils==null){
            synchronized (AppDataBaseUtils.class){
                appDataBaseUtils =new AppDataBaseUtils();
            }
        }
        return appDataBaseUtils;
    }
    private AppDataBase appDataBase;

    private MoneyDao moneyDao;


    public void init(Application application){
        appDataBase =Room.databaseBuilder(application,AppDataBase.class,TABLE_NAME)
                .allowMainThreadQueries()
                .build();
        moneyDao = appDataBase.moneyDao();

    }


    public MoneyDao getMoneyDao(){
        if(moneyDao==null){
            moneyDao = appDataBase.moneyDao();
        }
        return moneyDao;
    }




}
